/* March 22, 2024
This code reproduces the quantitative results in
Sarah F. Anzia and Jessica Trounstine, 
"Civil Service Adoption in America: The Political Influence of City Employees,"
American Political Science Review (forthcoming). */

* Load replication data

*** Reproduce numbers of cities of each type in text ***

* Number of cities for with *some* data on civil service status
codebook citystate if civserv~=. 

/* Number of cities for which civil service status is coded using 
year of adoption in 1940-44 Municipal Yearbooks */
codebook citystate if MYB_hasyearadopted==1 & civserv~=.

/* Number of cities with only 0s on civserv (never adopted) up through 1962:
447 cities with 0s throughout and an additional 9 cities that had 0s up through
1962 and then switched to having civil service after 1962 = 456 cities. */
egen meancivserv = mean(civserv), by(citystate)
codebook citystate if meancivserv==0
egen meancivserv2 = mean(civserv) if year<=1962, by(citystate)
codebook citystate if meancivserv~=. & meancivserv~=0 & meancivserv~=1 ///
	& MYB_hasyearadopted~=1 & meancivserv2==0

* Number of cities with only 1s on civserv but no year of adoption
codebook citystate if meancivserv==1

* Number of cities that adopted civil service 1945-1963
codebook citystate if meancivserv2~=. & meancivserv2~=0 & meancivserv2~=1 & MYB_hasyearadopted~=1

* Share of cities that had civil service by 1940
tab civserv if year==1940


*** Figures ***

* Figure 2: Year of Municipal Civil Service Adoption
histogram year_adopted if year==1962, ///
frequency bin(70) xtitle("") xlabel(1885(5)1960, ///
labsize(small) angle(forty_five)) ///
title(Figure 2: Year of Municipal Civil Service Adoption, ///
size(medsmall) color(black)) scheme(s2mono)

* Figure 3: Year of Municipal IAFF Establishment
hist iaffyear2 if year==1962 & iaffyear2<=1940, bin(40) freq ///
xtitle("") xlabel(1900(5)1940, ///
labsize(small)) title(Figure 3: Year of Municipal IAFF Establishment, ///
size(medsmall) color(black)) scheme(s2mono)

* Figure 4: (This produces the numbers for the bar chart.)
gen popbin=0 if lag10pop<25000 & lag10pop~=.
replace popbin=1 if lag10pop>=25000 & lag10pop<50000
replace popbin=2 if lag10pop>=50000 & lag10pop<100000
replace popbin=3 if lag10pop>=100000 & lag10pop~=.
tab popbin civserv if year==1940, row
tab popbin civserv if year==1940 & iaff==1, row
tab popbin civserv if year==1940 & iaff==0, row

* Figure 5: See data and layer files and replication instructions in README.txt

*** Tables ***

* Table 1: Descriptive Statistics, by Civil Service Status

* Number of 1940 city observations with demographic variables
codebook citystate if year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=.

* Proportion with IAFF locals, by 1940 civil service status
tabstat iaff if citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., ///
stat(mean) by(civserv)

* Proportion with any known union local, by 1940 civil service status
tabstat anyunion1940 if citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., ///
stat(mean count) by(civserv)

* Average city population, by 1940 civil service status
tabstat lag10pop if citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., ///
stat(mean count) by(civserv)

* Average proportion foreign born, by 1940 civil service status
tabstat lag10foreign if citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., ///
stat(mean count) by(civserv)

* Average proportion illiterate, by 1940 civil service status
tabstat lag10pctilliterate if citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., ///
stat(mean count) by(civserv)

* Average propotion Black, by 1940 civil service status
tabstat lag10pctblack if citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., stat(mean) by(civserv)

* Proportion without/with civil service in West
tab civserv if west==1 & citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=.

* Proportion without/with civil service in Midwest
tab civserv if midwest==1 & citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=.

* Proportion without/with civil service in Northeast
tab civserv if northeast==1 & citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=.

* Proportion without/with civil service in South
tab civserv if south==1 & citystate~="" & year==1940 & civserv~=. & lnlag10pop~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=.


* Table 2: Municipal Civil Service by 1940

* Table 2 column 1
reg civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstable2, se starlevel(10 5 1) replace

* Table 2 column 2
reg civserv anyunion1940 lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstable2, se starlevel(10 5 1) merge

* Generate variable = 1 if IAFF or firebenev
gen iafffirebenev = 1 if iaff==1 | firebenev==1
replace iafffirebenev = 0 if iaff==0 & (firebenev==0 | firebenev==.)

* Table 2 column 3
reg civserv iafffirebenev lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstable2, se starlevel(10 5 1) merge

* Table 2 column 4
reg civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack  i.fips_st if year==1940  ///
, cluster(state)
outreg using cstable2, se starlevel(10 5 1) merge


* Table 3: Employee Organization and Municipal Civil Service

set matsize 4000

* Table 3 column 1
xtreg civserv iaff i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstable3, se starlevel(10 5 1) replace

* Table 3 column 2
xtreg civserv iaff afscme i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstable3, se starlevel(10 5 1) merge

* Table 3 column 3
xtreg civserv iaff lnpop if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstable3, se starlevel(10 5 1) merge

* Table 3 column 4
xtreg civserv iaff lnpop i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstable3, se starlevel(10 5 1) merge

* Table 3 column 5
xtreg civserv iaff afscme lnpop i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstable3, se starlevel(10 5 1) merge


* Table 4: Mining

* Table 4 column 1
xi: reg iaff lnmining lnpop if year==1920, cluster(state)
outreg using mining, se starlevel(10 5 1) replace

* Table 4 column 2
xi: reg iaff lnmining lnpop i.region if year==1920, cluster(state)
outreg using mining, se starlevel(10 5 1) merge

* Table 4 column 3
xi: reg iaff lnmining lnpop i.state if year==1920, cluster(state)
outreg using mining, se starlevel(10 5 1) merge

* Table 4 column 4
xi: reg iaff lnmining lnpop i.region if year==1940, cluster(state)
outreg using mining, se starlevel(10 5 1) merge


*** ONLINE APPENDIX ***
* Figure A1: See data and layer files and replication instructions in README.txt

/* Figure A2: Proportion of cities adopting civil service by year
This produces the number of cities that had adopted civil service by each year
from 1884 to 1961. In addition to the 914 that had adopted by 1962, 
there are 325 cities known to have not had civil service as of 1962 (see text).
The numbers in Figure A2 are therefore the number of civil service
adoptions in that year divided by (914+325)=1,239 cities. */
tab year_adopted if year==1962

/* Figure A3: IAFF establishments and total number of work stoppages, 1916-1940
This produces the number of IAFF establishments each year, from 1916
to 1940. (These numbers are the same as those shown in Figure 3 of the
main paper.) The number of work stoppages by year come from the 
US Bureau of Labor Statistics (1947); see online appendix. */
tab iaffyear2 if year==1940 & iaffyear2<=1940

* Table A1: Table 2, Logistic Regression  

* Column 1
logit civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstableA1, se starlevel(10 5 1) replace

* Column 2
logit civserv anyunion1940 lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstableA1, se starlevel(10 5 1) merge

* Column 3
logit civserv iafffirebenev lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstableA1, se starlevel(10 5 1) merge

* Column 4
logit civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack  i.fips_st if year==1940  ///
, cluster(state)
outreg using cstableA1, se starlevel(10 5 1) merge


* Table A2: Table 2, excluding cases of approximated adoption date

* Column 1
reg civserv_strict iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstableA2, se starlevel(10 5 1) replace

* Column 2
reg civserv_strict anyunion1940 lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstableA2, se starlevel(10 5 1) merge

* Column 3
reg civserv_strict iafffirebenev lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstableA2, se starlevel(10 5 1) merge

* Column 4
reg civserv_strict iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack  i.fips_st if year==1940  ///
, cluster(state)
outreg using cstableA2, se starlevel(10 5 1) merge


/* Table A3: Lags, semiparametric estimation, 
excluding early-adopting states, city employment */

* Column 1: 1-year lag
reg civserv l.iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstableA3, se starlevel(10 5 1) replace

* Column 2: 5-year lag
reg civserv l5.iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940  ///
, cluster(state)
outreg using cstableA3, se starlevel(10 5 1) merge

* Column 3: Semiparametric (log population) note requires installation of Stata package st0278.pkg
semipar civserv iaff lag10foreign lag10pctilliterate lag10pctblack ///
statelaw1940 northeast south midwest if year==1940, cluster(state) nonpar(lnlag10pop)
outreg using cstableA3, se starlevel(10 5 1) merge

* Column 4: Excluding early adopting states
reg civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940 & state~="NY" & state~="MA" & state~="OH"  ///
, cluster(state)
outreg using cstableA3, se starlevel(10 5 1) merge

* Column 5: With logged # of city employees
reg civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 l.lntotalemp i.region if year==1940   ///
, cluster(state)
outreg using cstableA3, se starlevel(10 5 1) merge


* Table A4: Interactions, IAFF and city population

* center city population
summarize lnlag10pop if year==1940 & civserv~=. & lag10foreign~=. ///
& lag10pctilliterate~=. & lag10pctblack~=. & iaff~=., detail
gen clnlag10pop = lnlag10pop - 9.851408

* Column 1
reg civserv iaff clnlag10pop c.clnlag10pop#c.iaff lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940, cluster(state)
outreg using cstableA4, se starlevel(10 5 1) replace

* Column 2
reg civserv anyunion1940 clnlag10pop c.clnlag10pop#c.anyunion1940 lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940, cluster(state)
outreg using cstableA4, se starlevel(10 5 1) merge

* Column 3
gen popbin2=0 if lag10pop<5000 & lag10pop~=.
replace popbin2=1 if lag10pop>=5000 & lag10pop<10000
replace popbin2=2 if lag10pop>=10000 & lag10pop<25000
replace popbin2=3 if lag10pop>=25000 & lag10pop<50000
replace popbin2=4 if lag10pop>=50000 & lag10pop<100000
replace popbin2=5 if lag10pop>=100000 & lag10pop~=.

reg civserv iaff popbin2 c.popbin2#c.iaff lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940, cluster(state)
outreg using cstableA4, se starlevel(10 5 1) merge

* Column 4

* create popquint variable 
summarize lnlag10pop if citystate!="" & year==1940 & civserv~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., detail

centile lnlag10pop if citystate!="" & year==1940 & civserv~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., centile(20)
gen popquint=0 if lnlag10pop<=9.120656 & year==1940 & lnlag10pop~=.

centile lnlag10pop if citystate!="" & year==1940 & civserv~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., centile(40)
replace popquint=1 if lnlag10pop>9.120656 ///
& lnlag10pop<=9.447544 & year==1940 & lnlag10pop~=.

centile lnlag10pop if citystate!="" & year==1940 & civserv~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., centile(60)
replace popquint=2 if lnlag10pop>9.447544 ///
& lnlag10pop<=9.827448 & year==1940 & lnlag10pop~=.

centile lnlag10pop if citystate!="" & year==1940 & civserv~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., centile(80)
replace popquint=3 if lnlag10pop>9.827448 ///
& lnlag10pop<=10.58197 & year==1940 & lnlag10pop~=.

replace popquint=4 if lnlag10pop>10.58197 & year==1940 & lnlag10pop~=.

reg civserv iaff popquint c.popquint#c.iaff lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940, cluster(state)
outreg using cstableA4, se starlevel(10 5 1) merge

* Column 5

* identify log population outliers
summarize lnlag10pop if citystate~="" & year==1940 & civserv~=. ///
& lag10foreign~=. & lag10pctilliterate~=. & lag10pctblack~=., detail

di 9.231025 - 1.5*(10.34445-9.231025)
di 10.34445 + 1.5*(10.34445-9.231025)

reg civserv iaff clnlag10pop c.clnlag10pop#c.iaff lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940 & ///
lnlag10pop>=7.5608875 & lnlag10pop<=12.014587, cluster(state)
outreg using cstableA4, se starlevel(10 5 1) merge

* Column 6 
reg civserv iaff clnlag10pop c.clnlag10pop#c.iaff lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 i.region if year==1940 & ///
lag10pop>=10000, cluster(state)
outreg using cstableA4, se starlevel(10 5 1) merge


* Table A5: Additional two-way fixed effects models

* Column 1
xtreg civserv iaff i.year if year<=1940 & year>=1900 ///
& lnpop~=., fe cluster(citystate)
outreg using cstableA5, se starlevel(10 5 1) replace

* Column 2
xtreg civserv iaff lnpop i.year if year<=1940 & year>=1890, fe cluster(citystate)
outreg using cstableA5, se starlevel(10 5 1) merge

* Column 3
xtreg civserv iaff lnpop i.year if year<=1940 & year>=1910, fe cluster(citystate)
outreg using cstableA5, se starlevel(10 5 1) merge

* Column 4
gen popgrowth=lnpop-l10.lnpop
xtreg civserv iaff popgrowth i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstableA5, se starlevel(10 5 1) merge

* Column 5
xtreg civserv iaff lnpop i.year if year<=1940 & year>=1900 ///
& state~="NY" & state~="MA" & state~="OH", fe cluster(citystate)
outreg using cstableA5, se starlevel(10 5 1) merge


* Table A6: IAFF lags and leads

* Column 1
xtreg civserv l1.iaff lnpop i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstableA6, se starlevel(10 5 1) replace

* Column 2
xtreg civserv l2.iaff lnpop i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstableA6, se starlevel(10 5 1) merge


* Column 3
xtreg civserv l5.iaff lnpop i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstableA6, se starlevel(10 5 1) merge

* Column 4
xtreg civserv l1.iaff f1.iaff lnpop i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstableA6, se starlevel(10 5 1) merge

* Column 5
xtreg civserv l1.iaff l2.iaff f1.iaff f2.iaff lnpop i.year if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstableA6, se starlevel(10 5 1) merge


* Table A7: Estimates by decade

* Column 1: 1910-1919
xtreg civserv iaff lnpop i.year if year<=1919 & year>=1910, fe cluster(citystate)
outreg using cstableA7, se starlevel(10 5 1) replace

* Column 2: 1920-1929
xtreg civserv iaff lnpop i.year if year<=1929 & year>=1920, fe cluster(citystate)
outreg using cstableA7, se starlevel(10 5 1) merge

* Column 3: 1930-1939
xtreg civserv iaff lnpop i.year if year<=1940 & year>=1930, fe cluster(citystate)
outreg using cstableA7, se starlevel(10 5 1) merge


* Table A8: Pretrends

* create cohorts
egen maxiaff1940 = max(iaff) if year<=1940, by(citystate)
gen cohort = 0 if maxiaff1940==0
replace cohort = 1900 if iaffyear2>=1900 & iaffyear2<=1919 & iaffyear2~=.
replace cohort = 1920 if iaffyear2>=1920 & iaffyear2<=1929 & iaffyear2~=.
replace cohort = 1930 if iaffyear2>=1930 & iaffyear2<=1940 & iaffyear2~=.

* Numbers for first column of Table A8
tabstat civserv if year==1899 & (state~="NY" & ///
state~="MA" & state~="OH"), by(cohort)

* Numbers for second column of Table A8
tabstat civserv if year==1919 & (state~="NY" & ///
state~="MA" & state~="OH"), by(cohort)

* Numbers for third column of Table A8
tabstat civserv if year==1929 & (state~="NY" & ///
state~="MA" & state~="OH"), by(cohort)

* For text: csdid results (Calloway and Sant'Anna 2020)
csdid civserv iaff lnpop if year>=1900 ///
 & year<=1940, [ivar(citystatenum)] time(year) gvar(cohort)

csdid civserv iaff lnpop if year>=1900 ///
 & year<=1940, [ivar(citystatenum)] time(year) gvar(cohort) notyet
 
estat pretrend
estat simple
estat group


* Table A9
pwcorr iaff reform pctatlarge nonpartisan if year==1940


* Table A10: Reform Institutions and Machines

* Column 1
reg civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 reform pctatlarge nonpartisan i.region if year==1940  ///
, cluster(state)
outreg using cstableA10, se starlevel(10 5 1) replace

* Column 2
reg civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 reform2 i.region if year==1940  ///
, cluster(state)
outreg using cstableA10, se starlevel(10 5 1) merge

* Column 3
reg civserv iaff lnlag10pop lag10foreign lag10pctilliterate ///
lag10pctblack statelaw1940 bias2_machine i.region if year==1940  ///
, cluster(state)
outreg using cstableA10, se starlevel(10 5 1) merge


* Table A11

* Column 1
reg iaff lnlag10pop lag10foreign lag10pctilliterate lag10pctblack statelaw1940 i.region if year==1940, cluster(state)
outreg using cstableA11, se starlevel(10 5 1) replace

*column 2
 reg iaff lnlag10pop lag10foreign lag10pctilliterate lag10pctblack i.fips_st if year==1940, cluster(state)
outreg using cstableA11, se starlevel(10 5 1) merge

*column 3 
xtreg iaff lnpop if year<=1940 & year>=1900, fe cluster(citystate)
outreg using cstableA11, se starlevel(10 5 1) merge


